using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using LibrErian.Data;


using LibrErian.Model;

namespace LibrErian
{
	public partial class frmMain : Form
	{
		public frmMain()
		{
			InitializeComponent();
		}

		private void frmMain_Load(object sender, EventArgs e)
		{
			log4net.Config.XmlConfigurator.Configure();

			LoadBooks();
		}

		private void dgvBooks_DoubleClick(object sender, EventArgs e)
		{
			if(dgvBooks.SelectedRows.Count > 0)
			{
				Book selectedBook = (Book)dgvBooks.SelectedRows[0].DataBoundItem;
				frmEditBook editForm = new frmEditBook();
				editForm.EditBook(selectedBook);
				editForm.ShowDialog();
			}
		}

		private void btnNew_Click(object sender, EventArgs e)
		{
			New();
		}

		private void tsbNew_Click(object sender, EventArgs e)
		{
			New();
		}
		
		private void New()
		{
			frmEditBook editForm = new frmEditBook();
			if(editForm.ShowDialog() == DialogResult.OK)
			{
				LoadBooks();
			}
		}
		
		private void LoadBooks()
		{
			dgvBooks.DataSource = NHibernateManager.GetBooks();
		}
	}
}